class Reconnect extends egret.DisplayObjectContainer {
	money: number;
	private context;
	private speed = .1;
	public textField;

	public constructor(context: any) {
		super();
		this.context = context;
		this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
	}

	private onAddToStage(event: egret.Event) {
		this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
		new Bg(this, 'mask_in_png');
		var percentage = 0.65;
		this.touchEnabled = true;
		this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);

		//加载主面板
		var imgCon = [];
		imgCon['url'] = 'reconnect_bg_png';
		imgCon['width'] = this.stage.stageWidth * 0.60;
		imgCon['height'] = this.stage.stageHeight * 0.7;
		imgCon['y'] = this.stage.stageHeight * 0.15;
		imgCon['x'] = this.stage.stageWidth * 0.2;
		this.addChild(new ImageBitmap(imgCon).getImgPoint());

		this.textField = new egret.TextField();
		this.textField.y = this.stage.stageHeight * 0.63;
		this.textField.x = this.stage.stageWidth * 0.06;
		this.textField.width = 800;
		this.textField.height = 200;
		this.textField.textAlign = "center";
		this.textField.textColor = 0xFFFFE0;
		this.textField.size = 35;
		this.textField.text = "9";
		this.textField.fontFamily = "KaiTi";
		this.addChild(this.textField);



		this.alpha = 1;
		// this.openAm();
		var point = this;
		setInterval(function () {
			if (point.textField.text < 1) {
				location.replace(location.href);
				return;
			}
			point.textField.text -= 1;

		}, 1000);
	}

	public openAm(): void {
		this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
		this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
	}
	public closeAm(): void {
		this.removeEventListener(egret.Event.ENTER_FRAME, this.closeFrameHandler, this);
		this.addEventListener(egret.Event.ENTER_FRAME, this.closeFrameHandler, this);
	}
	/**打开时逐帧运动*/
	private enterFrameHandler(event: egret.Event): void {
		if (this.alpha < 1) {
			this.alpha += this.speed;
		} else {
			this.pauseOpenAm();
		}
	}

    /**
     * 关闭时动画运动
     * @param event
     */
	private closeFrameHandler(event: egret.Event): void {
		if (this.alpha > 0) {
			this.alpha -= this.speed;
		} else {
			this.pauseOpenAm();
			if (this.parent) {
				this.parent.removeChild(this);
				// this.context.complete();
				location.replace(location.href);
			}
		}
	}
	/**暂停打开时动画*/
	public pauseOpenAm(): void {
		this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
	}

	/**暂停关闭时的动画*/
	public pauseCloseAm(): void {
		this.removeEventListener(egret.Event.ENTER_FRAME, this.closeFrameHandler, this);
	}

	private onClose() {
		if (this.alpha < 1) {
			return;
		}
		this.closeAm();
	}
}